package servicio;

import java.net.InetAddress;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import remoto.Igestion;

public class BS {

	public void publicarServicio() {
    	try {
    		Igestion stub = new Gestion();
			LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			Naming.rebind("//localhost/Gestion", stub);
            verVinculos();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }

	public void verVinculos() {
        try {

        	String[] vinculos = Naming.list( "" );
      	  System.out.print(InetAddress.getLocalHost().getHostAddress());
      	  for ( int i = 0; i < vinculos.length; i++ ){
      		System.out.println( vinculos[i] );
      	  }
      	  System.out.print( ">>> Servicio publicado");
        }
        catch (Exception e) {
      	  e.printStackTrace();
        }
     }
    
    public void cerrar() {
		try {
			Naming.unbind("Gestion");
		} catch (Exception e) {
		} finally {
			System.exit(0);
		}
    }

}
